package net.it721;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.util.RecordFormatException;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        for(int i = 100000; i < 1000000; i++) {
            String password = "" + i;
            try (InputStream inputStream = new FileInputStream("[请输入您的文件路径]")) {
                Biff8EncryptionKey.setCurrentUserPassword(password);
                Workbook workbook = WorkbookFactory.create(inputStream);
            } catch (EncryptedDocumentException e) {
                continue;
            } catch (RecordFormatException e){
                System.out.println(password);
            }catch (Exception e) {
                e.printStackTrace();
                return ;
            }
            System.out.println(password);
            return;
        }
        System.out.println("没有找到密码");
    }
}
